<template>
{{#if ctrl.psSysPFPlugin}}
   {{> @macro/plugins/widget/widget-use.hbs appPlugin=ctrl.psSysPFPlugin}}
{{else}}
  <div :class="classNames" :id="controlID">
    <div class="control-content app-control-calendar__content">
      {{#if (eq ctrl.calendarStyle 'TIMELINE')}}
      {{!-- <AppCalendarTimeline :name="model.codeName" :store="store" style="{{#if ctrl.width}}width: {{ctrl.width}}px;{{/if}}{{#if ctrl.height}}height: {{ctrl.height}}px;{{/if}}" @click-event="ClickTimelineEvent"></AppCalendarTimeline> --}}
      {{else}}
      <AppCalendar ref="calendar" :name="model.codeName" :model="model" :class="classNames" :store="store" style="{{#if ctrl.width}}width: {{ctrl.width}}px;{{/if}}{{#if ctrl.height}}height: {{ctrl.height}}px;{{/if}}" @get-events="getEvents" @click-event="clickEvent">
      </AppCalendar>
      {{/if}}
    </div>
  </div>
{{/if}}
</template>

// 基于template/src/widgets/\{{appEntities}}/\{{ctrls@CALENDAR}}-calendar/\{{spinalCase ctrl.codeName}}-calendar.vue.hbs生成
<script setup lang="ts">
{{> @macro/plugins/widget/widget-import.hbs ctrl=ctrl}}
{{#if (eq ctrl.calendarStyle 'TIMELINE')}}
{{!-- import { AppCalendarTimeline } from '@components/widgets/calendar-timeline'; --}}
{{else}}
import { AppCalendar } from '@components/widgets/calendar';
{{/if}}  
import { model } from "./{{spinalCase ctrl.codeName}}-calendar-model";
import { IContext, IParam, createUUID, ILoadingHelper, ControlVOBase, CalendarActionType, ICtrlDataAction, ICalendarAbility, ICalendarController, ICalendarControllerParams, ICalendarStore, CalendarController, IViewCtx } from "@/core";
import { useNavParamsBind, useEventBind, getCtrlClassNames } from '@/hooks/use-ctrl';
import { Ref } from 'vue';  
import CalendarService from '@/core/modules/ctrl-service/calendar-service';
import { {{pascalCase ctrl.name}}ControlVO } from './{{spinalCase ctrl.codeName}}-calendar-vo';

{{> @macro/widgets/ctrl/ctrl-props.hbs
    props="openView?: Function;
    newView?: Function;
    actions: ICtrlDataAction;    
    selectFirstDefault?: boolean;
    "
}}

{{> @macro/common/emit.hbs name="ctrl" actionType="CalendarActionType" ability="ICalendarAbility"}}

const classNames = computed(() => {
    return getCtrlClassNames(model, props);
});

const calendar:Ref<IParam | null>= ref(null);


const controlID = createUUID();

const ctrlService = new CalendarService<ControlVOBase[]>({{pascalCase ctrl.name}}ControlVO, model.entityCodeName, {model})

const params: ICalendarControllerParams<CalendarActionType, ICalendarAbility> = {
    name: props.name,    
    model,
    evt,
    controlID,    
    pLoadingHelper: props.pLoadingHelper,    
    actions: props.actions,
    openView: props.openView,
    newView: props.newView,
    closeView: props.closeView,
    selectFirstDefault: props.selectFirstDefault,
    ctrlService: ctrlService,  
    handler: (data: ICalendarStore) => { return reactive(data); }
};

// 点击事件
const clickEvent = (arg: IParam) => {
    controller.onEventClick(arg);
}

// 加载事件
const getEvents = (arg: IParam, callback: Function) => {
    controller.load({arg, callback});
}

{{> @macro/common/controller.hbs name="ctrl" IController="ICalendarController" store="ICalendarStore" ability="ICalendarAbility" controller="CalendarController"}}  
</script>